using System;
using System.Collections;

namespace OracleInternal.Network
{
	internal class BadIPCache
	{
		private static long TenMinutes;

		private static Hashtable Cache;

		private static Hashtable Hosts;

		private static Hashtable Times;

		private static Hashtable HTime;

		static BadIPCache()
		{
			TenMinutes = 6000000000L;
			Cache = new Hashtable();
			Hosts = new Hashtable();
			Times = new Hashtable();
			HTime = new Hashtable();
		}

		internal static bool? Bad(string IP)
		{
			return BadIPorHost(IP, Cache, Times);
		}

		internal static bool? BadHost(string host)
		{
			return BadIPorHost(host, Hosts, HTime);
		}

		internal static void Insert(string IP, bool host = false)
		{
			if (host)
			{
				InsertIPorHost(IP, Hosts, HTime);
			}
			else
			{
				InsertIPorHost(IP, Cache, Times);
			}
		}

		internal static void Delete(string IP, Hashtable theCache, Hashtable theTimes)
		{
			lock (theCache)
			{
				theCache.Remove(IP);
				theTimes.Remove(IP);
			}
		}

		private static bool? BadIPorHost(string IP, Hashtable theCache, Hashtable theTimes)
		{
			long? num = (long?)theTimes[IP];
			if (num.HasValue && DateTime.Now.Ticks - num > TenMinutes)
			{
				Delete(IP, theCache, theTimes);
			}
			return ((bool?)theCache[IP]).GetValueOrDefault();
		}

		private static void InsertIPorHost(string IP, Hashtable theCache, Hashtable theTimes)
		{
			lock (theCache)
			{
				theCache[IP] = true;
				theTimes[IP] = DateTime.Now.Ticks;
			}
		}
	}
}
